// pages/detail/detail.js
var app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    petList:[
      {
        petImg: "../../image/pet/pet_banner_1.jpg"
      },
      {
        petImg: "../../image/pet/pet_banner_2.jpg"
      },
      {
        petImg: "../../image/pet/pet_banner_3.jpg"
      }
    ],
    url: app.globalData.commonUrl,
    circular: true,
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 5000,
    duration: 1500,
    petId:'',
    petInfo:{},
    petTypeName: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that = this;
      that.petId = options.petId;
      that.detailPet();
  },
  detailPet: function(){
    let that = this;
    let _petInfo, _petTypeName;
    wx.showToast({
      title: '加载中！',
      icon: 'loading',
      duration: 1000
    });
    let fn = res => {
      if(res.data.code == 200){
        _petInfo = res.data.data;
        let petType = _petInfo.petType;
        if(petType == 1){
          _petTypeName = '狗狗';
        }else{
          _petTypeName = petType == 2 ? '猫猫':'其他小动物';
        }
      }
      that.setData({
        petInfo: _petInfo,
        petTypeName: _petTypeName
      })
    }
    app.ajax('/petAdopt/list/detail?id=' + that.petId, 'get', '', fn)
  },
  applyPet: function(){
    wx.navigateTo({
      url: '/pages/applyInfo/applyInfo',
    })
  },
  goIndex: function(){
    wx.switchTab({
      url: '/pages/index/index',
    })
  },
  phoneCall: function (e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.contactPhone,
      success: function () {
        //console.log("成功拨打电话")
      },
      error: function () {
        // console.log("2222")
      }
    })
  },
  createPoster: function (e) {
    let petId = e.currentTarget.dataset.petId;
    wx.navigateTo({
      url: '/pages/poster/poster?petId='+petId,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})